package com.panfeng.xcloud.common.core.page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * 分页公交响应model
 *
 * @author xiaobo
 * @version 1.0
 * @since 2018-12-28
 */
public class PageResponse<T extends Serializable> implements Serializable {
    private int totalCount = 0;
    private int totalPage = 1;
    private int pageNumber = 1;
    private int pageSize = 500;
    private List<T> items = new ArrayList();

    public PageResponse() {
    }

    public void measureTotalPage(int totalCount, int pageSize) {
        this.totalCount = totalCount;
        if (totalCount >= 1) {
            this.totalPage = (totalCount + pageSize - 1) / pageSize;
        }
    }

    public int getTotalCount() {
        return this.totalCount;
    }

    public int getTotalPage() {
        return this.totalPage;
    }

    public List<T> getItems() {
        return this.items;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getFirstNo() {
        return (pageNumber - 1) * pageSize + 1;
    }

    public long getLastNo() {
        if (pageNumber < totalPage) {
            return pageNumber * pageSize;
        } else {
            return totalCount;
        }
    }

}
